import React, { Component } from 'react'
import memoryUtils from '../../utils/memoryUtils'
import {Redirect, Route, Switch} from 'react-router-dom'
import { Layout } from "antd";
import Header from '../../components/header/header'
import LeftNav from '../../components/left-nav/left-nav'

import Home from "../home/home";
import Category from "../category/category";
import Product from "../product/product";
import Role from "../role/role";
import User from "../user/user";
import Bar from "../charts/bar";
import Line from "../charts/line";
import Pie from "../charts/pie";



const {Footer,  Sider, Content } = Layout;

export default class Admin extends Component {
    render() {
        // 如果内存中没有当前登录用户的信息,说明没有登录,所以跳转到登录页
        const user = memoryUtils.user;
        if (!user || !user._id) {
            // 在render()中如何自动跳转
            return <Redirect to="/login" />
        } 
        return (
          <Layout style={{ height: "100%" }}>
            <Sider>
              <LeftNav />
            </Sider>
            <Layout>
              <Header>heder</Header>
              <Content style={{margin: 20, background: "#fff" }}>
                <Switch>
                  <Route path="/home" component={Home} />
                  <Route path="/category" component={Category} />
                  <Route path="/product" component={Product} />
                  <Route path="/role" component={Role} />
                  <Route path="/user" component={User} />
                  <Route path="/charts/bar" component={Bar} />
                  <Route path="/charts/line" component={Line} />
                  <Route path="/charts/pie" component={Pie} />
                  <Redirect to="/home" />
                </Switch>
              </Content>
              <Footer style={{ textAlign: "center", color: "#ccc" }}>
                推荐使用谷歌浏览器,可以获得更佳页面操作体验
              </Footer>
            </Layout>
          </Layout>
        );
    }
}
